package service

import (
	"context"
	"fmt"
	__ "user-srv/basic/proto"
	"user-srv/handler/dao"
)

// 用户资料添加
func (s *Server) UserProfileCreated(_ context.Context, in *__.UserProfileCreatedReq) (*__.UserProfileCreatedResp, error) {
	if in.UserId <= 0 || in.NickName == "" || in.Email == "" || in.Gender < 0 || in.Signature == "" {
		return nil, fmt.Errorf("参数错误")
	}

	UserProfile, err := dao.UserProfileCreated(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.UserProfileCreatedResp{
		Id: int32(UserProfile.Id),
	}, nil
}

// 用户资料修改
func (s *Server) UserProfileUpdated(_ context.Context, in *__.UserProfileUpdatedReq) (*__.UserProfileUpdatedResp, error) {
	if in.UserId <= 0 || in.NickName == "" || in.Email == "" || in.Gender < 0 || in.Signature == "" {
		return nil, fmt.Errorf("参数错误")
	}

	UserProfile, err := dao.UserProfileUpdate(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.UserProfileUpdatedResp{
		UserId: UserProfile.UserId,
	}, nil
}

// 用户资料详情
func (s *Server) UserProfileDetail(_ context.Context, in *__.UserProfileDetailReq) (*__.UserProfileDetailResp, error) {
	if in.UserId <= 0 {
		return nil, fmt.Errorf("参数错误")
	}
	UserProfileDetail, err := dao.UserProfileDetail(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.UserProfileDetailResp{
		UserId:    UserProfileDetail.UserId,
		NickName:  UserProfileDetail.NickName,
		Gender:    UserProfileDetail.Gender,
		Email:     UserProfileDetail.Email,
		Signature: UserProfileDetail.Signature,
	}, nil
}
